package com.project.practice11_24.service.impl;

import com.project.practice11_24.mapper.IManMapper;
import com.project.practice11_24.mapper.IStudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.Reader;

@Service
public class BaseService {
    private static SqlSessionFactory factory;
    private SqlSession session ;
    //使用代理方式得到Mapper接口实现类对象
    static {
        try {
            Reader r = Resources.getResourceAsReader("mybatis.cfg.xml");
            factory = new SqlSessionFactoryBuilder().build(r);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public SqlSession getSession(){
        return factory.openSession();
    }

    public void setSession(SqlSession session) {
        this.session = session;
    }

}
